const { getOptions } = require("loader-utils");
const { validate } = require("schema-utils");

const schema = require("../schema/loader01-schema.json");

// NormalLoader
// 异步Loader
module.exports = function (content, sourcemap, meta) {
  console.log(content, "lyc-loader01");

  // 获取传入参数
  const options = getOptions(this);
  console.log("optionse: ", options);

  validate(schema, options, {
    name: "lyc-loader01",
    age: "lyc-loader02",
  });

  const callback = this.async();

  setTimeout(() => {
    callback(null, content);
  }, 2000);
};

// 同步Loader
// module.exports = function (content, sourcemap, meta) {
//   console.log(content, "lyc-loader01");

//   // 同步loader，两种方式返回数据
//   // return content + 123;
//   this.callback(null, content);
// };

// PitchLoader
module.exports.pitch = function () {
  console.log("loader pitch 01");
};
